External Entities

External entities are entities (storage objects) that are not part of your document.  When we originally talked about XML structure, there were two facets:

Logical – the logical order of elements in a document.
Physical – the physical location of content.

These two can be very different.  Whenever an XML processor processes a document, it is working with the logical structure as one entity.  However, that one logical entity may be physically broken into multiple physical entities (files/documents).

This is possible because you can declare external entities within your XML document and include them so that they are treated like one document.  In effect, they become one logical entity, even though they are multiple entities.

The syntax for declaring an external entity is:

<!ENTITY entity.name SYSTEM|PUBLIC “URI”>

Let’s break down this syntax.  The first item is the <!ENTITY> declaration tag.  The next is entity name that you define.  The next item is either the SYSTEM or PUBLIC keywords, which we will describe in a moment.  Finally, the Uniform Resource Identifier (URI) that points to the external entity is specified.  A URI is just like a Uniform Resource Locator (URL), but has more capability.  URI’s can be fully qualified or relative.  The typical structure of a URI is:

protocol://login-name:password@host:port/path

The protocol is optional and can specify a number of network protocols including Internet protocols.  The login and password are optional, and if not specified, anonymous access is attempted.  Finally, the path the absolute or relative path to the external entity.  For example, if we wanted to include a document from a web site, the following would be valid:

<!ENTITY doc1 SYSTEM “http://www.mysrver.com/doc1.xml”>